<?php

class PXFPaginator
{
	public
		$params = null,
		$disp   = null,
		$page   = null,
		$count  = null,
		$range  = null,
		$from   = null;

	function __construct($count,$params)
	{
		if(!array_key_exists('c',$params))
			$params['c'] = PXFInstance::$controller;

		if(!array_key_exists('a',$params))
			$params['a'] = PXFInstance::$action;
		
		$tmp_params = array();
		foreach($params as $key => $value)
		{
			$tmp_params[] = sprintf('%s=%s',$key,$value);
		}
		$this->params = join('&',$tmp_params);
		$this->disp   = PXFRequest::reqGetOrDefault('disp',PXFConfig::PRODUCTS_PER_PAGE);
		$this->page   = PXFRequest::reqGetOrDefault('pge',0); 
		$this->count  = $count;
		$this->number = ceil($count / $this->disp) - 1;
		$this->number = ($this->number < 0) ? 0 : $this->number;
		$this->range  = range(0,$this->number);
		$this->from   = $this->page * $this->disp;
	}
}
?>
